package com.seckill.redis;

import cn.hutool.core.thread.ThreadUtil;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;

/**
 * @author yangjunwei
 * @date 2022/5/10 8:08 下午
 */
@Slf4j
public class CacheDeleteHandler {

    /**
     * 定时线程池
     */
    private static final ScheduledThreadPoolExecutor SCHEDULED_EXECUTOR =
        ThreadUtil.createScheduledExecutor(1);

    public static void addCacheDeleteTask(KeyPrefix keyPrefix, String key, int delay) {
        log.error("CacheDeleteHandler add task, keyPrefix:{},key:{}", keyPrefix.getPrefix(), key);
        SCHEDULED_EXECUTOR.schedule(new CacheDeleteTask(keyPrefix, key), delay, TimeUnit.SECONDS);
    }


}
